package cn.edu.lcu.cs.architecture.mvc.usermanage.model;

import cn.edu.lcu.cs.architecture.mvc.usermanage.entity.User;
import cn.edu.lcu.cs.architecture.mvc.usermanage.service.UserService;
import cn.edu.lcu.cs.architecture.mvc.usermanage.service.UserServiceImpl;
import cn.edu.lcu.cs.architecture.mvc.usermanage.util.Observable;


public class UserInfoModel extends Observable {
    private UserService userService = new UserServiceImpl();
    private User user; // 模型数据，据此更新页面上用户详情信息
    private String msg; // 模型数据，页面上显示的消息提示

    /**
     * 显示用户详情
     *
     * @param id
     */
    public void showInfo(Long id) {
        user = userService.findById(id);
        msg = ""; // 清除消息提示
        notifyObservers(user);
    }

    /**
     * 设置编辑成功或失败时的消息
     *
     * @param msg
     */
    public void setMsg(String msg) {
        this.msg = msg;
        notifyObservers(msg);
    }
}
